// 题目链接：https://www.luogu.com.cn/problem/P1451

#include <iostream>

using namespace std;

const int N = 105;
const int M = 105;

char g[N][M];
int n, m;
int res = 0;
bool st[N][M];

int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

void DFS(int x, int y)
{
    for (int i = 0; i < 4; ++i)
    {
        int next_x = x + dx[i];
        int next_y = y + dy[i];

        // 剪枝
        if (next_x < 0 || next_x >= n || next_y < 0 || next_y >= m)
            continue;
        if (g[next_x][next_y] == '0')
            continue;
        if (st[next_x][next_y])
            continue;

        st[next_x][next_y] = true;
        DFS(next_x, next_y);
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> g[i];
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (g[i][j] != '0' && st[i][j] == false)
            {
                st[i][j] = true;
                ++res;
                DFS(i, j);
            }
        }
    }

    cout << res << endl;

    return 0;
}